package com.lcy.reggie.common;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.lcy.reggie.utils.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * ======刘春春大帅逼======
 * ******java学习之旅******
 */

/**
 *  自定义元数据对象处理器
 */

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     *  当执行添加操作的时候，触发
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("createUser", BaseContext.getCurrentId());
        metaObject.setValue("updateUser", BaseContext.getCurrentId());
    }

    /**
     * 当执行修改操作的时候，触发
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", BaseContext.getCurrentId());

    }
}
